// java --classpath ./test.jar com.torben.test.echoClient

package com.torben.test;

import java.net.*;
import java.io.*;

public class echoClient {

  public static void main(String[] args) {

    Socket theSocket;
    String hostname;
    DataInputStream theInputStream;
    DataInputStream userInput;
    PrintStream theOutputStream;
    String theLine;

    if (args.length > 0) {
      hostname = args[0];
    }
    else {
      hostname = "localhost";
    }

    System.out.println("Open for business");
    try {
    userInput = new DataInputStream(System.in);
    
      while (true) {
    	theSocket = new Socket(hostname, 80);
        theInputStream = new DataInputStream(theSocket.getInputStream());
        theOutputStream = new PrintStream(theSocket.getOutputStream());
          
        theLine = userInput.readLine();
        if (theLine.equals(".")) break;
        theOutputStream.println(theLine);
        System.out.println(theInputStream.readLine());
      }
    }  // end try
    catch (UnknownHostException e) {
      System.err.println(e);
    }
    catch (IOException e) {
      System.err.println(e);
    }

  }  // end main

}  // end echoClient
